package com.example.demo.controller;
import java.util.HashMap;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.entify.Order;
import com.example.demo.result.Result;
import com.example.demo.result.ResultFactory;
import com.example.demo.service.OrderService;
import com.example.demo.service.ncesService;

@RestController
@CrossOrigin
@RequestMapping("/nces")
public class ncesController {
	   @Autowired
	   private ncesService ncesService;
	    @Autowired
	    private OrderService orderService;	   
	@GetMapping("/ncesOlders")
	private Result ncesOlders(String adminName) {
		List<Order>olderList =orderService.Allolders();
		Integer OLderSum = olderList.size();
		List<Order> olderCount = ncesService.olderCount();
		int adminOlders = ncesService.adminOlder(adminName);
		HashMap<String, Object> hs = new HashMap<>();
		hs.put("OLderSum", OLderSum);
		hs.put("olderCount", olderCount);	
		hs.put("adminOlders", adminOlders);	
		return ResultFactory.buildSuccessFactory(hs);
    } 
	@GetMapping("/ncesUser")
	private Result ncesUser() {
		int Allusers= ncesService.Alluser();
		int Allworkers = ncesService.Allworkers();
		int Allcustomers = ncesService.Allcustomer();
		int DispatchWorkers = ncesService.DispatchWorkers();
		
		HashMap<String, Object> hs = new HashMap<>();
		hs.put("Allusers",Allusers);	
		hs.put("Allworkers",Allworkers);
		hs.put("Allcustomers",Allcustomers);
		hs.put("DispatchWorkers",DispatchWorkers);
		
		return ResultFactory.buildSuccessFactory(hs);
		
		
		
	}
	
	
	@GetMapping("/ncesTimeOlders")
	private Result ncesTimeOlders() {
		List<Order> finishList = ncesService.finish();
		List<Order> unfinishList = ncesService.unfinish();
		List<Order> totalList = ncesService.total();
		
		HashMap<String, Object> hs = new HashMap<>();
		
		hs.put("finishList", finishList);
		hs.put("unfinishList", unfinishList);
		hs.put("totalList", totalList);
		return ResultFactory.buildSuccessFactory(hs);
	}
	
	
	

}
